package com.ruoyi.carowner.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.carowner.domain.CarownerKm;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.carowner.domain.CarownerKmLog;
import com.ruoyi.carowner.service.ICarownerKmLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 兑换记录Controller
 * 
 * @author ruoyi
 * @date 2024-08-17
 */
@RestController
@RequestMapping("/carowner/log")
public class CarownerKmLogController extends BaseController
{
    @Autowired
    private ICarownerKmLogService carownerKmLogService;

    /**
     * 查询兑换记录列表
     */
    @PreAuthorize("@ss.hasPermi('carowner:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarownerKmLog carownerKmLog)
    {
        startPage();
        List<CarownerKmLog> list = carownerKmLogService.selectCarownerKmLogList(carownerKmLog);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('carowner:log:list')")
    @GetMapping("/getKmlt/{userId}")
    public TableDataInfo getKmlt(@PathVariable Integer userId) {
        startPage();
        List<CarownerKmLog> list = carownerKmLogService.selectKmlt(userId);
        System.out.println(list);
        return getDataTable(list);
    }

    @GetMapping("/getKmgt/{userId}")
    public TableDataInfo getKmgt(@PathVariable Integer userId) {
        startPage();
        List<CarownerKmLog> list = carownerKmLogService.selectKmgtByUserid(userId);
        System.out.println(list);
        return getDataTable(list);
    }



    /**
     * 导出兑换记录列表
     */
    @PreAuthorize("@ss.hasPermi('carowner:log:export')")
    @Log(title = "兑换记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarownerKmLog carownerKmLog)
    {
        List<CarownerKmLog> list = carownerKmLogService.selectCarownerKmLogList(carownerKmLog);
        ExcelUtil<CarownerKmLog> util = new ExcelUtil<CarownerKmLog>(CarownerKmLog.class);
        util.exportExcel(response, list, "兑换记录数据");
    }

    /**
     * 获取兑换记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('carowner:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(carownerKmLogService.selectCarownerKmLogById(id));
    }

    /**
     * 新增兑换记录
     */
    @PreAuthorize("@ss.hasPermi('carowner:log:add')")
    @Log(title = "兑换记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarownerKmLog carownerKmLog)
    {
        return toAjax(carownerKmLogService.insertCarownerKmLog(carownerKmLog));
    }

    /**
     * 修改兑换记录
     */
    @PreAuthorize("@ss.hasPermi('carowner:log:edit')")
    @Log(title = "兑换记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarownerKmLog carownerKmLog)
    {
        return toAjax(carownerKmLogService.updateCarownerKmLog(carownerKmLog));
    }

    /**
     * 删除兑换记录
     */
    @PreAuthorize("@ss.hasPermi('carowner:log:remove')")
    @Log(title = "兑换记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(carownerKmLogService.deleteCarownerKmLogByIds(ids));
    }
}
